/**
 * 作者: clz
 * 日期: 2025-04-17 14:48:10
 * 备注: 联盟建筑成员建设记录
 */
package com.motu.monstercity.server.game.userdata;

import com.motu.vertx.module.utility.model.BaseModel;
import com.motu.vertx.module.utility.model.Model;
import io.vertx.core.json.JsonObject;
import io.vertx.core.json.JsonArray;

public class UnionBuildUserRecordModel extends BaseModel implements Model {
	public static final String LISTKEY = "union_build_id.user_id";
	public static final int REDIS_EXPIRE_TIME = 0;// redis过期时间
	public static final int UPDATE_DB_TYPE = UPDATE_DB_TYPE_QUEUE;// 数据入库类型 队列入库
	public static final boolean ORDER_LIST = false;// 是否需要额外的有序列表

	protected long id; // 数据库id
	protected String unionBuildId = ""; // listkey (联盟id-建筑id)
	protected long userId; // 成员玩家id
	protected int dayBuildCost; // 当日建设
	protected int buildCost; // 历史总建设
	protected long resetTime; // 重置时间

	public void reset() {
	}

	protected String getKey() {
		return "UnionBuildUserRecord." + unionBuildId + "." + userId;
	}

	protected String getListKey() {
		return "UnionBuildUserRecord." + unionBuildId;
	}

	protected String getListItemKey() {
		return userId + "";
	}

	public void doCreate() {
		setTableId();
		insert();
	}

	public void setTableId() {
		putId(incrTableId("union_build_user_record"));
	}

	public JsonObject insert() {
		return super.insert(getKey(), id, REDIS_EXPIRE_TIME, UPDATE_DB_TYPE, LISTKEY, getListKey(), getListItemKey(), ORDER_LIST);
	}

	public void delete() {
		super.delete(getKey(), id, UPDATE_DB_TYPE, 0, LISTKEY, getListKey(), getListItemKey(), ORDER_LIST);
	}

	/**
	 * 根据入库类型更新
	 */
	public JsonObject update() {
		return super.update(getKey(), id, REDIS_EXPIRE_TIME, UPDATE_DB_TYPE, 0, getAllObj(), LISTKEY, getListKey(), getListItemKey());
	}

	/**
	 * 实时入队列
	 */
	public JsonObject updateQueueNow() {
		return super.update(getKey(), id, REDIS_EXPIRE_TIME, UPDATE_DB_TYPE, 0, getAllObj(), LISTKEY, getListKey(), getListItemKey());
	}

	public JsonObject getAllObj(){
		JsonObject obj = new JsonObject();
		obj.put("id", id); // 数据库id
		obj.put("unionBuildId", unionBuildId); // listkey (联盟id-建筑id)
		obj.put("userId", userId); // 成员玩家id
		obj.put("dayBuildCost", dayBuildCost); // 当日建设
		obj.put("buildCost", buildCost); // 历史总建设
		obj.put("resetTime", resetTime); // 重置时间
		return obj;
	}

	public long getId() {
		return id;
	}

	public void putId(long id) {
		if (this.id != id) {
			this.id = id;
			updateRedisHashField(getKey(), "id", this.id);
		}
	}

	public void addId(long value) {
		this.id += value;
		updateRedisHashField(getKey(), "id", this.id);
	}

	public String getUnionBuildId() {
		return unionBuildId;
	}

	public void putUnionBuildId(String unionBuildId) {
		if (!this.unionBuildId.equals(unionBuildId)) {
			this.unionBuildId = unionBuildId;
			updateRedisHashField(getKey(), "unionBuildId", this.unionBuildId);
		}
	}

	public long getUserId() {
		return userId;
	}

	public void putUserId(long userId) {
		if (this.userId != userId) {
			this.userId = userId;
			updateRedisHashField(getKey(), "userId", this.userId);
		}
	}

	public void addUserId(long value) {
		this.userId += value;
		updateRedisHashField(getKey(), "userId", this.userId);
	}

	public int getDayBuildCost() {
		return dayBuildCost;
	}

	public void putDayBuildCost(int dayBuildCost) {
		if (this.dayBuildCost != dayBuildCost) {
			this.dayBuildCost = dayBuildCost;
			updateRedisHashField(getKey(), "dayBuildCost", this.dayBuildCost);
		}
	}

	public void addDayBuildCost(int value) {
		this.dayBuildCost += value;
		updateRedisHashField(getKey(), "dayBuildCost", this.dayBuildCost);
	}

	public int getBuildCost() {
		return buildCost;
	}

	public void putBuildCost(int buildCost) {
		if (this.buildCost != buildCost) {
			this.buildCost = buildCost;
			updateRedisHashField(getKey(), "buildCost", this.buildCost);
		}
	}

	public void addBuildCost(int value) {
		this.buildCost += value;
		updateRedisHashField(getKey(), "buildCost", this.buildCost);
	}

	public long getResetTime() {
		return resetTime;
	}

	public void putResetTime(long resetTime) {
		if (this.resetTime != resetTime) {
			this.resetTime = resetTime;
			updateRedisHashField(getKey(), "resetTime", this.resetTime);
		}
	}

	public void addResetTime(long value) {
		this.resetTime += value;
		updateRedisHashField(getKey(), "resetTime", this.resetTime);
	}

}